try:
    from .parsing import task_nominal_to_symbolic
    from .type_schema import TypeSchema
    from .error import ProtocolError
except ImportError:
    from parsing import task_nominal_to_symbolic
    from type_schema import TypeSchema
    from error import ProtocolError


NominalTask = str

def jsonify(task: NominalTask) -> str:
    return task

class SymbolicTask:
    def __init__(self, name: str, input_type: TypeSchema, output_type: TypeSchema):
        self.name = name
        self.input_type = input_type
        self.output_type = output_type
    
    def __str__(self) -> str:
        return f"{self.name}:{self.input_type}->{self.output_type}"
    
    def short_str(self) -> str:
        return f"{self.name}:{self.input_type.short_str()}->{self.output_type.short_str()}"
    
    @classmethod
    def try_parse(cls, signature: str) -> 'SymbolicTask':
        name, input_type, output_type = task_nominal_to_symbolic(signature)
        return SymbolicTask(name, input_type, output_type)
    
    @classmethod
    def parse(cls, task: str) -> 'SymbolicTask':
        try:
            return cls.try_parse(task)
        except ProtocolError as e:
            raise ValueError(f"Failed to parse task schema: {task}")
